import {createSlice} from '@reduxjs/toolkit'
import axios from 'axios'
const shopcartSlice=createSlice({
    name:'shopcartNS',
    initialState:{
        shopcartList:[]
    },
    reducers:{
        SET_SHOPCART_LIST(state,action){
            console.log('------SET_SHOPCART_LIST---------');
            state.shopcartList=action.payload
        }
    }
})

export const getShopcartAsync=async(dispatch)=>{
    console.log('---------网络获取购物车信息-----------');
    const result=await axios.get('http://www.zhaijizhe.cn:3006/shopcart/getShopcartData')
    console.log('result',result.data);
    dispatch(SET_SHOPCART_LIST(result.data))
}


export const {SET_SHOPCART_LIST}=shopcartSlice.actions
export default shopcartSlice.reducer